﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using System.Drawing;

namespace DockSample.DAO
{
    class NFRChartPointDAO:BaseDAO
    {
        public void AddNFRChartPoint(NFRChartPoint pt, string chartId)
        {
            try
            {
                //       this.DeletePoint(nfr);
                //   this.conn = this.GetConnection();
                SQLiteCommand cmd = this.GetCmd();
                cmd.CommandText = "insert into NFRChartPoint( id ,OriginalNFRChartTypeId,x,y)  "
                    + "values ( @id ,@OriginalNFRChartTypeId,@x,@y)";
                cmd.Parameters.Add(new SQLiteParameter("id", pt.id));
                cmd.Parameters.Add(new SQLiteParameter("OriginalNFRChartTypeId", chartId));
              
                cmd.Parameters.Add(new SQLiteParameter("x", pt.point.X));

                cmd.Parameters.Add(new SQLiteParameter("y", pt.point.Y));

                cmd.ExecuteNonQuery();


            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            finally
            {
                this.CloseConnection();
            }

        }

        public List<NFRChartPoint> GetNFRChartPointByChartId(string chartId)
        {
            List<NFRChartPoint> list = new List<NFRChartPoint>();
            try
            {
               


                SQLiteCommand cmd = this.GetCmd();
                cmd.CommandText = "select * from NFRChartPoint where OriginalNFRChartTypeId=@OriginalNFRChartTypeId";
                cmd.Parameters.Add(new SQLiteParameter("OriginalNFRChartTypeId", chartId));
                SQLiteDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    int x=Convert.ToInt32(reader["x"]);
                    int y=Convert.ToInt32(reader["y"]);

                    Point point = new Point(x,y);

                    NFRChartPoint pt = new NFRChartPoint(point,reader["id"].ToString());
                    pt.OriginalNFRChartTypeId = chartId;

                    list.Add(pt);

                }

                

            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            finally
            {
                this.CloseConnection();
            }
            return list;
        }
    }
}
